package com.intelligentcar.springboot.service.serverImpl;

import com.intelligentcar.springboot.bean.Carrepair;
import com.intelligentcar.springboot.bean.Manager;
import com.intelligentcar.springboot.mapper.CarrepairMapper;
import com.intelligentcar.springboot.mapper.LogMapper;
import com.intelligentcar.springboot.service.CarrepairServer;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class CarrepairServerImpl implements CarrepairServer {
    @Autowired
    private  LogMapper logMapper;
    @Autowired
    private CarrepairMapper carrepairMapper;

    //查看车辆维修表的所有数据
    @Override
    public List<Carrepair> carrepair(RowBounds rowBounds) {
        return carrepairMapper.carrepair(rowBounds);
    }

    //查看车辆维修表中有几条数据
    @Override
    public int carrepairnum() {
        return carrepairMapper.carrepairnum();
    }

    //在维修车辆表中安排维修人员
    @Override
    public int arrangerepair(HttpServletRequest req, Carrepair carrepair) {
        req.getSession().setAttribute("userName","王五");
        String time =new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(new Date());
        String logUser = req.getSession().getAttribute("userName").toString();
        logMapper.addLog(time,"修改",logUser,"安排维修人员");
        return carrepairMapper.arrangerepair(carrepair);
    }

    //在维修车辆表中删除数据
    @Override
    public int deletecarrepair(HttpServletRequest req,Carrepair carrepair) {
        req.getSession().setAttribute("userName","王五");
        String time =new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(new Date());
        String logUser = req.getSession().getAttribute("userName").toString();
        logMapper.addLog(time,"删除",logUser,"删除维修车辆表数据");
        return carrepairMapper.deletecarrepair(carrepair);
    }

}
